/*
 * Copyright (c) 2010. Dylan Schell.
 */

package nl.xs4all.dylanschell.deckprinter;

import com.google.inject.Inject;
import com.google.inject.Injector;
import nl.xs4all.dylanschell.deckprinter.guice.WicketGuiceApp;
import nl.xs4all.dylanschell.deckprinter.pages.CardImageResource;
import nl.xs4all.dylanschell.deckprinter.pages.DecksPage;
import nl.xs4all.dylanschell.deckprinter.pages.UploadDeckPage;
import org.apache.wicket.Application;
import org.apache.wicket.Page;
import org.apache.wicket.WicketRuntimeException;
import org.apache.wicket.protocol.http.WebApplication;

public class DeckPrinterApplication extends WicketGuiceApp
{
    @Inject
    public DeckPrinterApplication(Injector injector)
    {
        super(injector);
    }

    @Override
    public String getConfigurationType()
    {
        return DEPLOYMENT;
    }


    @Override
    protected void init()
    {
        super.init();
        getSharedResources().add("card-images", new CardImageResource());
        mountBookmarkablePage("upload", UploadDeckPage.class);
        mountBookmarkablePage("decks", DecksPage.class);
    }

    @Override
    public Class<? extends Page> getHomePage()
    {
        return DecksPage.class;
    }

    public static DeckPrinterApplication get()
    {
        Application application = Application.get();

        if (!(application instanceof WebApplication))
        {
            throw new WicketRuntimeException(
                    "The application attached to the current thread is not a " +
                            DeckPrinterApplication.class.getSimpleName());
        }

        return (DeckPrinterApplication) application;
    }
}
